/* $Header: cmd_set.h,v 2.2 01/10/02 10:30:13 przybyls Exp $ */


/***********************************************************************/
/* INCLUDE FILE NAME: cmd_set.h                                        */
/* ==================                                                  */
/*                                                                     */
/* Author:  Bob Cook                                                   */
/*                                                                     */
/* COMMENT:                                                            */
/*          Include file for IQ command set                            */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef CMD_SET_H
#define CMD_SET_H

/*****************************/
/*   IFDEFS                  */
/*****************************/


/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

#define  LF        (BIT8)0x0A     /* line feed char */
#define  CR        (BIT8)0x0D     /* carriage return char */
#define MASK_7BITS (BIT8)0x7F     /* used to clear most signif bit */

#define RD_BIN_MSG_HDR_LEN  14  /* length of RD cmd's msg header- binary mode */

/* markers inserted in data stream by Signal Path */
#define  START_MARKER         (INT32)0x80000000
#define  STOP_MARKER          (INT32)0x80000001
#define  START_STOP_MARKER    (INT32)0x80000002

/* command characteristics */
#define  MAX_PARM_NUM      50     /* maximum number of parameters */
#define  MAX_PARM_LEN      300    /* maximum length of all parameter */
#define  SSAP_LEN          2      /* size of SSAP */
#define  DSAP_LEN          2      /* size of DSAP */
#define  OPCODE_LEN        2      /* size of IQ's instruction cmd */
#define  MIN_OPCODE_LEN    2      /* minimum size of instruction cmd */
#define  MAX_OPCODE_LEN    10     /* maximum size of instruction cmd */
#define  MSG_HDR_LEN       SSAP_LEN+DSAP_LEN+OPCODE_LEN+1 /* size of IQ's msg
                                             header including trailing space */

/* max number of points for binary SnRD cmd; less than 1000 bytes/msg */
/*    6 bytes/pt ; the pre data hdr = 20 bytes */
/*    (1000 - 20)/6 = about 160 points max */
#define  BIN_DATA_HDR_SIZE  20
#define  BIN_MAX_PT_SIZE  6

/* max number of points for hexadecimal SnRD cmd; less than 1000 bytes/msg */
/*    12 bytes/pt ; the pre data hdr = 40 bytes */
/*    (1000 - 40)/12 =  80 points max */
#define  HEX_DATA_HDR_SIZE  40
#define  HEX_MAX_PT_SIZE  12

/* max number of points for binary SnRD cmd set for less than 1000 bytes/msg */
/*   for 37 bits of significance the largest number is -137,438,953,472 or */
/*   13 char plus "," gives 14 char/pt; the pre data msg hdr = 46 */
/*   (1000 - 46)/14 = about 65 points max */
#define  DEC_DATA_HDR_SIZE  46
#define  DEC_MAX_PT_SIZE  14

/* max number of words for compressed SnRD cmd; less than 1000 bytes/msg */
/*    4 bytes/word ; the pre data hdr = 40 bytes */
/*    (1000 - 40)/4 =  240 words max */
#define  CMP_DATA_HDR_SIZE  40
#define  CMP_MAX_PT_SIZE  16

/* total number of paths avaiable for pass through commands */
#define  NUM_PATHS  16

/*****************************/
/*   MACROS                  */
/*****************************/

/*****************************/
/*   TYPEDEFS                */
/*****************************/



/* Define data structures for commands from the datacomm subsystem. */
typedef  struct  Cmd_Type
{
    struct Cmd_Type *next;              /* pointer to next buffer in queue */
    U_INT16   comm_port;                /* host port that command came from */
    union {
       BIT8      char_dsap[DSAP_LEN];    /* destination service access point */
       INT16     int_dsap;
    } dsap;
    union {
       BIT8      char_ssap[SSAP_LEN];    /* source service access point */
       INT16     int_ssap;
    } ssap;
    union {
       BIT8      char_op[MAX_OPCODE_LEN+1];     /* instruction opcode */
       INT16     int_op;
    } opcode;
    U_INT16   parmv[MAX_PARM_NUM+1];    /* gives number and position of parms */
    BIT8      parms[MAX_PARM_LEN];      /* parameter strings */
}  CMD_TYPE;


/* Define data structures for table to keep pass thru data paths. */
typedef  struct
{
    union {
       BIT8      char_idsap[DSAP_LEN];      /* 6890 instrument address */
       INT16     int_idsap;
    } idsap;
    union {
       BIT8      char_hdsap[DSAP_LEN];      /* host address for path */
       INT16     int_hdsap;
    } hdsap;
    U_INT16      host_port;                 /* host port for path */
}  PATH_TYPE;

/* define the status word for RD command */

typedef  struct
{
    unsigned               : 4;         /* bit 12-15 - not used */
    unsigned    buf_ovrflw : 1;         /* bit 11 - data buffer overflow occurred */
    unsigned    param_mod  : 1;         /* bit 10 - gc parameter modified */
    unsigned    gc_rdy     : 2;         /* bit 8-9  - gc readyness */
    unsigned    scc_state  : 1;         /* bit 7 - is scc run active */
    unsigned    run_state  : 3;         /* bits 4-6 - run state */
    unsigned    data_acq   : 1;         /* bit 3 - data acquisition on flag */
    unsigned    start_stop : 1;         /* bit 2 - a start and stop occurred */
                                        /*          without data point */
    unsigned    stop       : 1;         /* bit 1 - stop point in buffer */
    unsigned    start      : 1;         /* bit 0 - start point in buffer */
}  RD_STATUS_TYPE;


/* Define data structures for the response to a read cmd in binary mode. */
typedef  struct
{
    union
    {
       RD_STATUS_TYPE  bits;       /* status word */
       U_INT16         word;       /* treat status as one word */
    }status;
    U_INT32         pts_remaining; /* number of points in SigBuf and FrmtBuf */
    U_INT16         pt_count;      /* number of points in msg */
    U_INT16         start_pos;     /* position of start in data buffer */
    U_INT32         start_delta;   /* start delta in micro seconds */
}  RD_RESP_BIN_TYPE;


/* Define data structures for queue of command buffers.  */

typedef  struct
{
    CMD_TYPE  *head;           /* pointer to head of queue */
    CMD_TYPE  *tail;           /* pointer to tail of queue */
    U_INT16    num_entries;    /* number of entries in queue */
}  CMD_QUEUE_TYPE;

typedef union
{
        struct
        {
                unsigned MVPL    :1;
                unsigned MVKC    :1;
                unsigned MVKP    :1;
                unsigned MVKS    :1;
                unsigned MVEN    :1;
                unsigned MVPR    :1;
                unsigned StartRun:1;
        } bit;

        U_INT8  word;
} MV_FLAG_TYPE;

/* typedef used by IntToDec48 and RD command */
typedef union
{
   DIG_DATA dig_data;
   INT48    int48;
} NUM_TYPE;

/* temp buffer used by RD command */
typedef  struct
{
   RD_RESP_BIN_TYPE     hdr;      /* temp storage of header */

   union
   {
      union
      {
         BIT8              byte[6];
         INT16             word[3];
         INT48             int48;
         DIG_DATA          dig_data;
         NUM_TYPE          num_type;
      } point[1024];   /* temp storage of data for dec convert */

      U_INT16   compress[3072];
   } data;


} TMP_MSG_TYPE;


/*****************************/
/*   EXTERNS                 */
/*****************************/


/*****************************/
/*   FUNCTION PROTOTYPES     */
/*****************************/


void CmdProc(void);
void ExecuteWkFile(BIT8  *p_begin, U_INT16 length);
void GC_Cmds(void);
INT16 GCOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void S1_Cmds(void);
INT16 S1Opcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void S2_Cmds(void);
INT16 S2Opcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void SP_Cmds(void);
INT16 SPOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void SS_Cmds(void);
INT16 SSOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void OV_Cmds(void);
INT16 OVOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void IX_Cmds(void);
INT16 IXOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void CC_Cmds(void);
INT16 CCOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void DX_Cmds(void);
INT16 DXOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void CX_Cmds(void);
INT16 CXOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void AX_Cmds(void);
INT16 AXOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void VX_Cmds(void);
INT16 VXOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void IQ_Cmds(void);
INT16 IQOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void AS_Cmds(void);
INT16 ASOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void DT_Cmds(void);
INT16 DTOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len);
void TP_Cmds(void);
/* pass through functions */
void _0X_Cmds(void);
void PX_Cmds(void);


/* mv_cmds.c */
void DoMVPL(void);
void DoMVKC(INT32 ccomp);
void DoMVKP(void);
void DoMVKS(void);
void DoMVEN(void);
void DoMVPR(void);
void DoMVStartRun(void);
void Init_MV_Cmds(void);
void MV_Cmds(void);


/* cc_cmds.c */
INT16 DoCCID(BIT8 *p_resp_parm);

/* sx_cmds.c */
void InitializeSxRD(void);

/* pneu_tbls.c */
INT32 GetSmallZoneFlags (void *pzone);


#ifndef mccabe
#  pragma SECTION PROG=boot
#endif

void InitializeCmdProc(void);

#ifndef mccabe
#  pragma SECTION UNDO
#endif


#endif
